package com.scenic.rd_android.filelock;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.text.format.Formatter;
import android.view.View;

import com.nova.scenic.projectlibs.util.debug.MyLog;
import com.scenic.rd_android.R;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class FileActivity extends Activity {

    private static final String TAG = "FileActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_file);
    }



    int i = 1000 ;
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
    public void createFoldOrFile(View view){
        MyLog.i(TAG,"createFoldOrFile");

        File file = Environment.getExternalStorageDirectory();
        MyLog.i(TAG,"externalStorageDirectory is  " + file.getAbsolutePath());

        StatFs statFs = new StatFs(file.getAbsolutePath());
        MyLog.i(TAG, "statFs available blocks " + statFs.getAvailableBlocksLong());
        MyLog.i(TAG,"blackSize " + statFs.getBlockSizeLong());
        long available = statFs.getAvailableBlocksLong() * statFs.getBlockSizeLong();
        MyLog.i(TAG,"free size " + available + "  " + Formatter.formatFileSize(this,available));


        try {
            OutputStream outputStream = new FileOutputStream(new File(file,"cccc" + i++));
            byte[] buff = new byte[1024];
            for (int i = 0; i < buff.length; i++) {
                buff[i] = (byte) i;
            }
            outputStream.write(buff,0,buff.length);
            outputStream.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        File newFile = new File(file,"mmmmm");
        newFile.mkdirs();


    }





}
